import { Controller, Get, Post, Request, Res } from '@nestjs/common';
import {
  Request as ExpressRequest,
  Response as ExpressResponse,
} from 'express';
import { ProxyService } from './proxy/proxy.service';
@Controller()
export class ApiGatewayController {
  constructor(private readonly proxyService: ProxyService) {}

  @Get('/users/*')
  async proxyUserRequests(
    @Request() req: ExpressRequest,
    @Res() res: ExpressResponse,
  ) {
    return this.proxyService.forwardRequest('user-service', req, res);
  }

  @Get('/products/*')
  async proxyProductRequests(
    @Request() req: ExpressRequest,
    @Res() res: ExpressResponse,
  ) {
    return this.proxyService.forwardRequest('product-service', req, res);
  }

  @Post('/orders/*')
  async proxyOrderRequests(
    @Request() req: ExpressRequest,
    @Res() res: ExpressResponse,
  ) {
    return this.proxyService.forwardRequest('order-service', req, res);
  }
}
